#ifndef _POINT_H_
#define _POINT_H_

#include <math.h>

const float PI = 3.14159f;

template <class VALUE_TYPE>
class Position
{
public:
    
    enum FACE_TYPE
    {
        FACE_TYPE_LEFT = -1,
        FACE_TYPE_RIGHT = 1,
    };
    
	VALUE_TYPE X, Y ;
    FACE_TYPE face;
    

	VALUE_TYPE GetDistance (const Position& target)
	{
		return sqrt ((X-target.X)*(X-target.X)+(Y-target.Y)*(Y-target.Y)) ;
	}

    bool CheckDistance(const Position& target,int MonsterDistance)
    {
        VALUE_TYPE distance = GetDistance (target) ;
        
        if (MonsterDistance > distance)
		{
			return true;
		}else
        {
            return false;
        }
    }
    
    bool Step(const Position& targetPoint,const Position& lookPoint,VALUE_TYPE moveLen)
    {
        VALUE_TYPE distance = GetDistance (targetPoint) ;
        
		if(distance == 0)
			return true;
        
		if (moveLen> distance)
		{
			X = X;
			Y = Y;
			return true ;
            
		}else
		{
			X += (targetPoint.X-X)*moveLen/distance ;
			Y += (targetPoint.Y-Y)*moveLen/distance ;
            LookAtPoint(lookPoint);
			return false ;
		}
    }
    
    void LookAtPoint(const Position& lookPoint)
    {
        if (lookPoint.X > X) {
            face = FACE_TYPE_RIGHT;
        }
        else {
            face = FACE_TYPE_LEFT;
        }
    }

	Position (VALUE_TYPE x, VALUE_TYPE y):X(x),Y(y)
	{
        face = FACE_TYPE_RIGHT;
	}

	Position ()
	{
		X = 0;
		Y = 0;
        
        face = FACE_TYPE_RIGHT;
	}
} ;

typedef Position<float> fPoint ;


#endif